{% extends 'layout.html' %}


{% block content %}
    <div class="luffy-container">

        <div class="panel panel-default">
            <div class="panel-heading"><i class="fa fa-list-ul" aria-hidden="true"></i> 作业列表（注意：创建issue时请设置标签《作业》
                ，否则无法获取）
            </div>

            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>创建时间</th>
                    <th>提交人数</th>
                    <th style="width: 20%;">未提交人员</th>
                </tr>
                </thead>
                <tbody>
                {% for row in body_list %}
                    <tr>
                        <td><a target="_blank" href="{{ row.html_url }}">{{ row.title }}</a></td>
                        <td> {{ row.created_at|slice:"10" }} </td>
                        <td> {{ row.rate }} </td>
                        <td>
                            <div style="margin-bottom: 5px;">{{ row.uncommitted_user }}</div>
                            <button onclick="fetchCommentInfo(this,{{ cls_id }},'{{ row.number }}')"
                                    class="fetch-btn btn btn-xs btn-danger">
                                点击获取
                            </button>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>

        </div>


    </div>
{% endblock %}

{% block js %}
    <script>
        /*
        获取提交信息
         */
        function fetchCommentInfo(ths, clsId, number) {
            $(ths).text('加载中...').prop('disabled',true);
            $.ajax({
                url: "{% url fetch_comment_url_name %}",
                type: 'GET',
                data: {'cls_id': clsId, 'number': number},
                success: function (arg) {
                    if (arg.status) {
                        $(ths).prev().text(arg.data.uncommitted_user);
                        $(ths).parent().prev().text(arg.data.rate);
                    } else {
                        alert(arg.error);
                    }
                    $(ths).text('点击获取').prop('disabled',false);
                }
            })
        }
    </script>
{% endblock %}